package org.wlw.web.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.wlw.web.context.SystemContextInterceptor;

@Configuration//只要添加Configuration之后就会被读取
public class GolbalConfig implements WebMvcConfigurer {
    @Autowired
    private SystemContextInterceptor systemContextInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedHeaders("*")
                .allowedMethods("GET","POST","DELETE","OPTIONS","HEAD","PUT")
                .maxAge(3600);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //针对所有页面添加拦截器
        registry.addInterceptor(systemContextInterceptor).addPathPatterns("/**");
    }
}
